﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using ExamSystem.Mdeol;
namespace ExamSystem.DAL
{
    /// <summary>
    /// 数据访问层
    /// </summary>
    public class TuserDAL
    {
        /// <summary>
        /// 查询用户信息
        /// </summary>
        public List<Tuser> selecttuser()
        {
            List<Tuser> list = new List<Tuser>();
            string sql = "select * from tuser";
            DataSet ds= DBhepter.GetDataSet(sql);
            DataTable dt = ds.Tables[0];
            for (int i = 0; i < dt.Rows.Count;i++ )
            {
                DataRow dr = dt.Rows[i];
                int tuId = int.Parse(dr["tuId"].ToString());
                string tuName = dr["tuName"].ToString();
                string tuPwd = dr["tuPwd"].ToString();
                string tuSex = dr["tuSex"].ToString();
                string tuPhone =dr["tuPhone"].ToString();
                Tuser ts = new Tuser(tuId,tuName,tuPwd,tuSex,tuPhone);
                list.Add(ts);
            }
            return list;

        }



        //登录
        public Tuser islogin(string no, string pwd)
        {
            Tuser ts = null;
            string sql = "select * from tuser where tuname='" + no + "' and tupwd='" + pwd + "'";
            DataSet ds = DBhepter.GetDataSet(sql);
            DataTable dt = ds.Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                int tuid = (int)dr["tuid"];
                string tuname = dr["tuname"].ToString();
                string tupwd = dr["tupwd"].ToString();
                string tusex = dr["tusex"].ToString();
                string tuphone = dr["tuphone"].ToString();
                ts = new Tuser(tuid,tuname,tupwd,tusex,tuphone);

            }
            return ts;
        }
    }
}